﻿Option Explicit On
Option Strict On

Public Class Jugador
    Inherits Persona

    'Atributos
    Public Structure StrDireccion
        Dim calle As String
        Dim numero As Integer
        Dim piso As Integer
        Dim localidad As String
        Dim provincia As String
    End Structure

    Private _Nombre As String
    Private _Direccion As StrDireccion
    Private _Telefono As String
    Private _Dni As String
    Private _Email As String 'falta validar email
    Private _Whatsap As Boolean
    Private _Facebook As String 'falta validar email
    Private _Twitter As String 'falta validar email

    'Constructores
    Public Sub New()
        Me._Nombre = ""
        Me._Direccion.calle = ""
        Me._Direccion.numero = 0
        Me._Direccion.piso = 0
        Me._Direccion.localidad = ""
        Me._Direccion.provincia = ""
        Me._Telefono = ""
        Me._Dni = ""
        Me._Email = ""
        Me._Whatsap = False
        Me._Facebook = ""
        Me._Twitter = ""
    End Sub

    Public Sub New(ByVal nombre As String, ByVal calle As String, ByVal numero As Integer, ByVal piso As Integer, _
                   ByVal localidad As String, ByVal provincia As String, ByVal dni As String, _
                   ByVal telefono As String, ByVal whatsap As Boolean, ByVal facebook As String, _
                   ByVal twitter As String, ByVal email As String)

        'Valido nombre
        If (Validar(nombre, 30, True)) Then
            _Nombre = nombre
        Else
            Throw New ArgumentException("Campo nombre obligatorio")
        End If

        'Valido calle
        If (Validar(calle, 30, True)) Then
            _Direccion.calle = calle
        Else
            Throw New ArgumentException("Campo calle obligatorio")
        End If

        'Valido número
        If (numero > 0) Then
            _Direccion.numero = numero
        Else
            Throw New ArgumentException("Campo número obligatorio")
        End If

        Me._Direccion.piso = piso

        'Valido localidad
        If (Validar(localidad, 30, True)) Then
            _Direccion.localidad = localidad
        Else
            Throw New ArgumentException("Campo localidad obligatorio")
        End If

        'Valido provincia
        If (Validar(provincia, 30, True)) Then
            _Direccion.provincia = provincia
        Else
            Throw New ArgumentException("Campo provincia obligatorio")
        End If

        'Valido dni
        If (ValidarDNI(dni)) Then
            _Dni = dni
        Else
            Throw New ArgumentException("Campo Dni incorrecto")
        End If

        'Valido telefono
        If (ValidarTlf(telefono)) Then
            _Telefono = telefono
        Else
            Throw New ArgumentException("Campo Teléfono incorrecto")
        End If

        'Valido email
        If (ValidarEmail(email)) Then
            Me._Email = email
        Else
            Throw New ArgumentException("Campo email incorrecto")
        End If

        Me._Whatsap = whatsap
        Me._Facebook = facebook
        Me._Twitter = twitter

        'Insertar en base de datos
        'Dim bd As BaseDatos = New BaseDatos()
        'bd.open()
        'If bd.Insertar("INSERT INTO ...") <= 0 Then
        '    Throw New ArgumentException("No se insertaron datos")
        'End If
        'bd.close()
    End Sub

    'Destructores
    Public Sub Dispose()
        Me._Nombre = ""
        Me._Direccion = Nothing
        Me._Telefono = ""
        Me._Dni = ""
        Me._Whatsap = False
        Me._Facebook = ""
        Me._Twitter = ""
        Me._Email = ""
    End Sub

    Protected Overrides Sub finalize()
        Me._Nombre = ""
        Me._Direccion = Nothing
        Me._Telefono = ""
        Me._Dni = ""
        Me._Whatsap = False
        Me._Facebook = ""
        Me._Twitter = ""
        Me._Email = ""
    End Sub

    'Propiedades
    Public Property Nombre As String
        Get
            Return Me._Nombre
        End Get
        Set(value As String)
            If (Validar(value, 30, True)) Then
                _Nombre = value
            Else
                Throw New ArgumentException("Campo nombre obligatorio")
            End If
        End Set
    End Property

    Public Property Telefono As String
        Get
            Return Me._Telefono
        End Get
        Set(value As String)
            If (ValidarTlf(value)) Then
                _Telefono = value
            Else
                Throw New ArgumentException("Campo Teléfono incorrecto")
            End If
        End Set
    End Property

    Public Property Dni As String
        Get
            Return Me._Dni
        End Get
        Set(value As String)
            If (ValidarDNI(value)) Then
                _Dni = value
            Else
                Throw New ArgumentException("Campo Dni incorrecto")
            End If
        End Set
    End Property

    Public Property Email As String
        Get
            Return Me._Email
        End Get
        Set(value As String)
            If (ValidarEmail(value)) Then
                Me._Email = value
            Else
                Throw New ArgumentException("Campo Teléfono incorrecto")
            End If
        End Set
    End Property

    Public Property Whatsap As Boolean
        Get
            Return Me._Whatsap
        End Get
        Set(value As Boolean)
            Me._Whatsap = value
        End Set
    End Property

    Public Property Facebook As String
        Get
            Return Me._Facebook
        End Get
        Set(value As String)
            Me._Facebook = value
        End Set
    End Property

    Public Property Twitter As String
        Get
            Return Me._Twitter
        End Get
        Set(value As String)
            Me._Twitter = value
        End Set
    End Property

    'Métodos
    Public Overrides Function ToString() As String
        Return _Nombre & _Direccion.calle & _Direccion.numero & _Direccion.piso & _Direccion.localidad _
            & _Direccion.provincia & _Telefono & _Dni & _Email & _Whatsap & _Facebook & _Twitter
    End Function
End Class
